package config2excel.resolve;

import java.util.HashMap;
import java.util.Map;

import config2excel.bean.Address;
import config2excel.util.C2EList;
import config2excel.util.StringUtil;

public class ConfigAddress implements IConfigResolve {

  private Address address;

  private Map map;

  @Override
  public void ResolveConfig(String src) {
    src = src.trim();
    if (StringUtil.isStrBegin(src, "edit")) {
      address = new Address();
      map = new HashMap();
      src = src.replace("edit", "");
      // address.setName(src.trim());
      map.put("name", StringUtil.repalceQuotation(src).trim());
    } else if (src.equals("next")) {
      addressList.add(map);
      C2EList.addList.add(map);
    } else if (StringUtil.isStrBegin(src, "set associated-interface")) {
      src = src.replace("set associated-interface", "");
      // address.setAssociated_interface(src.trim());
      map.put("interface", StringUtil.repalceQuotation(src).trim());
    } else if (StringUtil.isStrBegin(src, "set type")) {
      src = src.replace("set type", "");
      // address.setType(src.trim());
      map.put("type", StringUtil.repalceQuotation(src).trim());
    } else if (StringUtil.isStrBegin(src, "set subnet")) {
      src = src.replace("set subnet", "");
      // address.setSubnet(src.trim());
      map.put("subnet", StringUtil.repalceQuotation(src).trim());
    } else if (StringUtil.isStrBegin(src, "set end-ip")) {
      src = src.replace("set end-ip", "");
      // address.setSubnet(src.trim());
      map.put("end-ip", StringUtil.repalceQuotation(src).trim());
      map.put("subnet", map.get("start-ip") + "-" + map.get("end-ip"));
      //      if(null!=map.get("start-ip")&&null == map.get("subnet")){
      //        map.put("subnet", map.get("start-ip")+"-"+map.get("end-ip"));
      //      }
    } else if (StringUtil.isStrBegin(src, "set start-ip")) {
      src = src.replace("set start-ip", "");
      map.put("start-ip", StringUtil.repalceQuotation(src).trim());
      map.put("subnet", map.get("start-ip") + "-" + map.get("end-ip"));
      //      if(null!=map.get("end-ip")&&null == map.get("subnet")){
      //        
      //      }
    }

    System.out.println("ResolveAddress------" + src.trim());
  }

}
